import requests
import json


def submit(index, code):
    # 请求地址
    baseurl = 'http://acm.nefu.edu.cn/post/problem/submitWritePost.php'
    # 请求参数
    data = {
        'problem': index,
        'language': 1,
        'code': code
    }

    # 请求头
    headers = {
        'Host': 'acm.nefu.edu.cn',
        'Connection': 'keep-alive',
        'Accept': '*/*',
        'X-Requested-With': 'XMLHttpRequest',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Origin': 'http://acm.nefu.edu.cn',
        'Cookie': 'your Cookie',
        'Referer': 'http://acm.nefu.edu.cn/problemShow.php?problem_id='+str(index)
    }

    # 进行请求
    try:
        res = requests.post(baseurl, data=data, headers=headers)
        js = json.loads(res.text)
    except:
        return False

    return js['status'] == 1
